package com.gitee.wsl.jvm.exception


open class JobNotFoundException(message: String?) : RuntimeException(message) {
    /*constructor(jobDetails: JobDetails) : this(jobDetails.getClassName(),
        jobDetails.getMethodName(),
        jobDetails.getJobParameters().stream()
            .map { jobParameter: JobParameter -> toJobParameterClassName(jobParameter) }
            .toArray { _Dummy_.__Array__() },
        jobDetails.getJobParameters().stream()
            .anyMatch { x -> x.getObject() is JobParameterNotDeserializableException })*/

    constructor(
        clazz: Class<*>,
        methodName: String,
        parameterTypes: Array<Class<*>>
    ) : this(
        clazz.name,
        methodName,
        parameterTypes.map { obj -> obj.name }.toTypedArray(),
        /*Stream.of<Class<*>>(*parameterTypes).map<String> { obj: Class<*> -> obj.name }
            .toArray<String> { _Dummy_.__Array__() },*/
        false
    )

    constructor(
        className: String,
        methodName: String,
        parameterTypes: Array<String>,
        isJobParameterNotDeserializableException: Boolean
    ) : this(
        "$className.$methodName(" + java.lang.String.join(
            ",",
            *parameterTypes
        ) + ")" + (if (isJobParameterNotDeserializableException
        ) "\n\tcaused by: one of the JobParameters is not deserializable anymore"
        else "")
    )

    init {
        this.stackTrace = arrayOfNulls(0)
    }

    companion object {
        /*private fun toJobParameterClassName(jobParameter: JobParameter): String {
            if (jobParameter.getObject() is JobParameterNotDeserializableException) {
                return (jobParameter.getObject() as JobParameterNotDeserializableException).getClassName()
            }
            return jobParameter.getClassName()
        }*/
    }
}
